using System;
using System.Collections.Generic;
using System.Text;

namespace SavedVariablesParser {
    /// <summary>
    /// Provides an exception that traces specific line parser errors.
    /// </summary>
    public class LineParserException : ApplicationException{
        private string line = string.Empty;
        private int lineNumber = 0;

        /// <summary>
        /// 	<para>Initializes an instance of the <see cref="LineParserException"/> class.</para>
        /// </summary>
        /// <param name="line">The line that caused the exception.</param>
        /// <param name="lineNumber">The line number of the line that caused the exception.</param>
        public LineParserException(string line, int lineNumber) : base(FormatMessage(line, lineNumber)) {
            this.line = line;
            this.lineNumber = lineNumber;
        }

        /// <summary>
        /// The line that caused the exception.
        /// </summary>
        /// <param name="line">The l</param>
        /// <param name="lineNumber">The line number of the line that caused the exception.</param>
        /// <returns>The message to associate with the exception.</returns>
        private static string FormatMessage(string line, int lineNumber) {
            StringBuilder builder = new StringBuilder();
            builder.Append("The line specified could not be parsed or does not adhere to the formatting specification for saved variable files.");
            builder.Append("Line: ");
            builder.Append(lineNumber);
            builder.Append(", Text: \"");
            builder.Append(line);
            builder.Append("\"");
            return builder.ToString();
        }

        /// <summary>
        /// The line that caused the exception.
        /// </summary>
        public string Line {
            get {
                return this.line;
            }
        }
        
        /// <summary>
        /// The line number of the line that caused the exception.
        /// </summary>
        public int LineNumber {
            get {
                return this.lineNumber;
            }
        }
    }
}
